package order

import (
	"APi/client"
	"APi/request"
	"APi/response"
	"github.com/gin-gonic/gin"
	order "order_srv/proto"
)

func AddOrder(c *gin.Context) {
	var data request.OrderAddRequest
	userid := c.GetUint("userId")
	if err := c.ShouldBind(&data); err != nil {
		response.CurrencyErrResponse(c, 101, err.Error())
		return
	}
	res, err := client.OrderAdd(c, &order.OrderAddRequest{
		Userid:        int64(userid),
		MealProductId: int64(data.MealProductId),
		Num:           int64(data.Num),
		PayType:       int64(data.PayType),
		CouponId:      int64(data.CouponId),
		Comment:       data.Comment,
	})
	if err != nil {
		response.CurrencyErrResponse(c, -1, err.Error())
		return
	}
	response.CurrencySuccessResponse(c, "下单成功", map[string]interface{}{"pay_url": res.PayUrl})
}
